//
//  TopView.m
//  第六组电影项目
//
//  Created by mini on 14-7-4.
//  Copyright (c) 2014年 www.skedu.com.cn北京尚德智远科技有限公司. All rights reserved.
//

#import "TopView.h"
#import "ItemView.h"
#import "RatingView.h"
#import "TopModel.h"
#import "CommentViewController.h"

@implementation TopView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self initSubViews];
        // Initialization code
    }
    return self;
}

-(void)initSubViews
{
    itemView1=[[ItemView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height-15)];
    itemView1.item.frame=CGRectMake(0, 0, itemView1.width, itemView1.height);
    
    itemView1.title.frame=CGRectMake(0, itemView1.item.height-20, itemView1.width, 20);
    itemView1.title.font=[UIFont boldSystemFontOfSize:12];
    itemView1.title.textColor=[UIColor whiteColor];
    itemView1.title.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
    itemView1.backgroundColor=[UIColor clearColor];
    
    itemView1.delegate=self;
    
    rating=[[RatingView alloc]initWithFrame:CGRectMake(0, itemView1.title.bottom, self.width, 0)];
    rating.style=kSmallStyle;
    rating.backgroundColor=[UIColor yellowColor];
    
    [self addSubview:itemView1];
    [self addSubview:rating];
}

-(void)setTopModel:(TopModel *)topModel
{
    _topModel=topModel;
    itemView1.title.text=_topModel.title;
    
    NSString *imageStr=[_topModel.images objectForKey:@"medium"];
    [itemView1.item setImageWithURL:[NSURL URLWithString:imageStr] placeholderImage:[UIImage imageNamed:@"13"]];
    
    rating.ratingData=[_topModel.rating floatValue];
}

-(void)didItemView:(ItemView *)itemView atIndex:(NSInteger)index
{
    id next=[itemView nextResponder];
    
    Class cla = NSClassFromString(@"UIViewController");

    while (next!=nil)
    {
        next=[next nextResponder];
        if ([next isKindOfClass:cla])
        {
            UIViewController *top=(UIViewController *)next;
            CommentViewController *comment=[[CommentViewController alloc]init];
            [top.navigationController pushViewController:comment animated:YES];
            break;
        }
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
